package command;

import javax.naming.Context;
import javax.naming.InitialContext;
import javax.naming.NamingException;
import javax.sql.DataSource;

/**
 * Get the DataSource by name("java:comp/env/<b>{name}</b>")
 * @author Jeff Zhuo
 *
 */
public class DataSourceUtil {
	
	
	/**
	 * Get the DataSource
	 * @param name The name of DataSource(such as "jdbc/source")
	 * @return
	 */
	public static DataSource getDataSource(String name) {
		Context context;
		DataSource source = null;
		try {
			context = new InitialContext();
			source = (DataSource) context.lookup("java:comp/env/"+ name);

		} catch (NamingException e) {
			e.printStackTrace();
		}
		return source;
	}
}
